﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace App
{
    public partial class frmSupplier : Form
    {
        string list = "";
        int n;
        private bool IsQuery = true;
        Entities db = new Entities();
        T_Factory m_Factory = null;
        private int m_factory = 0;
        private int factory
        {
            set
            {
                var list = db.T_Factory.Where(a=>a.fID==value);
                foreach(var factorylist in list)
                {
                    m_Factory = factorylist;
                    break;
                }
                if (m_Factory == null) return;
                txtfactory.Text=m_Factory.factory;
                txtfShort.Text = m_Factory.fShort;
                txtfactoryFullName.Text = m_Factory.factoryFullName;
                txtfactoryFullNameEn.Text = m_Factory.factoryFullNameEn;
                txtaddressEn.Text = m_Factory.addressEn;
                txtaddress.Text = m_Factory.address;
                txtlineNumber.Text = m_Factory.lineNumber.ToString();
                txtdayProduct.Text = m_Factory.dayProduct.ToString();
                txtlineLength.Text = m_Factory.lineLength.ToString();
                txtzcNumber.Text = m_Factory.zcNumber;
                txtyearProduct.Text = m_Factory.yearProduct.ToString();
                //txt13.Text = m_Factory.factory;//主要客户贸易商
                //txt14.Text = m_Factory.factory;//该客户的主要市场和品牌
                txtkpzl.Text = m_Factory.kpzl;
                txtbankRoll.Text = m_Factory.bankRoll.ToString();
                txtphone.Text = m_Factory.phone;
                txtfax.Text = m_Factory.fax;
                txtemail.Text = m_Factory.email;
                txthomepage.Text = m_Factory.homepage;
                txtpost.Text = m_Factory.post;
                txtworkNumber.Text = m_Factory.workNumber.ToString();
                txtmanageNumber.Text = m_Factory.manageNumber.ToString();
                //txtsh.Text = m_Factory.factory;//税号
                txtpartnerStruct.Text = m_Factory.partnerStruct;
                txtrmbBank.Text = m_Factory.rmbBank;
                txtrmbAccount.Text = m_Factory.rmbAccount;
                txtusdBank.Text = m_Factory.usdBank;
                txtusdAccount.Text = m_Factory.usdAccount;
                txtcreditLevel.Text = m_Factory.creditLevel;
                //txtremark1.Text = m_Factory.factory;//备注
                //txtml1.Text = m_Factory.factory;//面料
                //txtml2.Text = m_Factory.factory;
                //txtml3.Text = m_Factory.factory;
                //txtdd1.Text = m_Factory.factory;//大底
                //txtdd2.Text = m_Factory.factory;
                //txtdd3.Text = m_Factory.factory;
                //txttop1.Text = m_Factory.factory;//最高
                //txttop2.Text = m_Factory.factory;
                //txttop3.Text = m_Factory.factory;
                //txtavg1.Text = m_Factory.factory;//平均
                //txtavg2.Text = m_Factory.factory;
                //txtavg3.Text = m_Factory.factory;
                //txtlow1.Text = m_Factory.factory;//最低
                //txtlow2.Text = m_Factory.factory;
                //txtlow3.Text = m_Factory.factory;
                txtdesignNumber.Text = m_Factory.designNumber.ToString();
                txtmDesignLongevity.Text = m_Factory.mDesignLongevity;
                txtchangeNumber.Text = m_Factory.changeNumber.ToString();
                txtdevolopNumber.Text = m_Factory.devolopNumber.ToString();
                txtqcNumber.Text = m_Factory.qcNumber.ToString();
                txtdaySample.Text = m_Factory.daySample.ToString();
                txtbmMaterial.Text = m_Factory.bmMaterial;
                txtaccessory.Text = m_Factory.accessory;
                txtoutFactory.Text = m_Factory.outFactory;
                txttprNumber.Text = m_Factory.tprNumber.ToString();
                txttprCanLoad.Text = m_Factory.tprCanLoad;
                txttprDayProduct.Text = m_Factory.tprDayProduct.ToString();
                txtmNumber.Text = m_Factory.mNumber.ToString();
                txtmCanLoad.Text = m_Factory.mCanLoad;
                txtmDayProduct.Text = m_Factory.mDayProduct.ToString();
                txtrbNumber.Text = m_Factory.rbNumber.ToString();
                txtrbCanload.Text = m_Factory.rbCanload;
                txtrbDayProduct.Text = m_Factory.rbDayProduct.ToString();
                txtsNumber.Text = m_Factory.sNumber.ToString();
                txtsCanLoad.Text = m_Factory.sCanLoad;
                txtsDayProduct.Text = m_Factory.sDayProduct.ToString();
                txtthx.Text = m_Factory.thx;
                txtthxDayProduct.Text = m_Factory.thxDayProduct.ToString();
                txtremark3.Text = m_Factory.remark;
                txtmName.Text = m_Factory.mName;
                txtmPhone.Text = m_Factory.mPhone;
                txtmFax.Text = m_Factory.mFax;
                txtmAccountName.Text = m_Factory.mAccountName;
                txtmBank.Text = m_Factory.mBank;
                txtmAccount.Text = m_Factory.mAccount;
                cbKind.Text = m_Factory.Kind;
                cbgQcName.Text = m_Factory.gQcName;
                cbyName.Text = m_Factory.yName;
                cbxQcName.Text = m_Factory.xQcName;
                if (m_Factory.isComplete == "是") rbisCompleteship1.Checked = true;
                if (m_Factory.factoryStatus == "启用") rbfactoryStatus1.Checked = true;
                //for (int i = 0; i < m_Factory.checkDevice.Length; i++)
                //{
                //    if (m_Factory.mainProduct[i] == 1) clbmainProduct.SetItemChecked(i, true);
                //}
                if (m_Factory.mainProduct[0] == 1) clbmainProduct.SetItemChecked(0, true);
                if (m_Factory.mainProduct[1] == 1) clbmainProduct.SetItemChecked(1, true);
                if (m_Factory.mainProduct[2] == 1) clbmainProduct.SetItemChecked(2, true);
                if (m_Factory.mainProduct[3] == 1) clbmainProduct.SetItemChecked(3, true);
                if (m_Factory.mainProduct[4] == 1) clbmainProduct.SetItemChecked(4, true);
                if (m_Factory.mainProduct[5] == 1) clbmainProduct.SetItemChecked(5, true);
                if (m_Factory.mainProduct[6] == 1) clbmainProduct.SetItemChecked(6, true);
                if (m_Factory.mainProduct[7] == 1) clbmainProduct.SetItemChecked(7, true);
                if (m_Factory.mainProduct[8] == 1) clbmainProduct.SetItemChecked(8, true);
                if (m_Factory.mainProduct[9] == 1) clbmainProduct.SetItemChecked(9, true);
                if (m_Factory.mainProduct[10] == 1) clbmainProduct.SetItemChecked(10, true);

                //for (int i = 0; i < m_Factory.checkDevice.Length; i++)
                //{
                //    if (m_Factory.checkDevice[i] == 1) chbcheckDevice.SetItemChecked(i, true);
                //}
                if (m_Factory.checkDevice[0] == 1) chbcheckDevice.SetItemChecked(0, true);
                if (m_Factory.checkDevice[1] == 1) chbcheckDevice.SetItemChecked(1, true);
                if (m_Factory.checkDevice[2] == 1) chbcheckDevice.SetItemChecked(2, true);
                if (m_Factory.checkDevice[3] == 1) chbcheckDevice.SetItemChecked(3, true);
                if (m_Factory.checkDevice[4] == 1) chbcheckDevice.SetItemChecked(4, true);
                if (m_Factory.checkDevice[5] == 1) chbcheckDevice.SetItemChecked(5, true);
                if (m_Factory.checkDevice[6] == 1) chbcheckDevice.SetItemChecked(6, true);
                if (m_Factory.checkDevice[7] == 1) chbcheckDevice.SetItemChecked(7, true);
                if (m_Factory.checkDevice[8] == 1) chbcheckDevice.SetItemChecked(8, true);
                if (m_Factory.checkDevice[9] == 1) chbcheckDevice.SetItemChecked(9, true);
            }
        }
        private void gvID()
        {
            try
            {
                if(gvlist.RowCount>0)
                {
                    int index = gvlist.CurrentRow.Index;
                    m_factory = Convert.ToInt32(gvlist.Rows[index].Cells["colfID"].Value.ToString());
                    factory = Convert.ToInt32(gvlist.Rows[index].Cells["colfID"].Value.ToString());
                }
                else
                {
                    TxtClear();
                }
            }
            catch (Exception exp)
            {

                Msg.ShowError(exp.Message.ToString()+exp.Source.ToString());
            }
        }
        private void SaveAdd()
        {
            m_Factory = new T_Factory();
            if (db.T_Factory.Count() <= 0) m_Factory.fID = 1;
            else m_Factory.fID = db.T_Factory.OrderByDescending(a => a.fID).First().fID + 1;
            m_Factory.factory=txtfactory.Text;
            m_Factory.fShort=txtfShort.Text;
            m_Factory.factoryFullName=txtfactoryFullName.Text;
            m_Factory.factoryFullNameEn=txtfactoryFullNameEn.Text;
            m_Factory.addressEn=txtaddressEn.Text;
            m_Factory.address=txtaddress.Text;
            if (!string.IsNullOrEmpty(txtlineNumber.Text)) m_Factory.lineNumber = int.Parse(txtlineNumber.Text);
            if (!string.IsNullOrEmpty(txtdayProduct.Text)) m_Factory.dayProduct = int.Parse(txtdayProduct.Text);
            if (!string.IsNullOrEmpty(txtlineLength.Text)) m_Factory.lineLength = int.Parse(txtlineLength.Text);
            m_Factory.zcNumber=txtzcNumber.Text;
            if (!string.IsNullOrEmpty(txtyearProduct.Text)) m_Factory.yearProduct = int.Parse(txtyearProduct.Text);
            //txt13.Text = m_Factory.factory;//主要客户贸易商
            //txt14.Text = m_Factory.factory;//该客户的主要市场和品牌
             m_Factory.kpzl=txtkpzl.Text;
            if(!string.IsNullOrEmpty(txtbankRoll.Text)) m_Factory.bankRoll=int.Parse(txtbankRoll.Text);
            m_Factory.phone=txtphone.Text;
            m_Factory.fax=txtfax.Text;
            m_Factory.email=txtemail.Text;
            m_Factory.homepage=txthomepage.Text;
            m_Factory.post=txtpost.Text;
            if (!string.IsNullOrEmpty(txtworkNumber.Text)) m_Factory.workNumber = int.Parse(txtworkNumber.Text);
            if (!string.IsNullOrEmpty(txtmanageNumber.Text)) m_Factory.manageNumber = int.Parse(txtmanageNumber.Text);
            //txtsh.Text = m_Factory.factory;//税号
            m_Factory.partnerStruct=txtpartnerStruct.Text;
            m_Factory.rmbBank=txtrmbBank.Text;
            m_Factory.rmbAccount=txtrmbAccount.Text;
            m_Factory.usdBank=txtusdBank.Text;
            m_Factory.usdAccount=txtusdAccount.Text;
            m_Factory.creditLevel=txtcreditLevel.Text;
            //txtremark1.Text = m_Factory.factory;//备注
            //txtml1.Text = m_Factory.factory;//面料
            //txtml2.Text = m_Factory.factory;
            //txtml3.Text = m_Factory.factory;
            //txtdd1.Text = m_Factory.factory;//大底
            //txtdd2.Text = m_Factory.factory;
            //txtdd3.Text = m_Factory.factory;
            //txttop1.Text = m_Factory.factory;//最高
            //txttop2.Text = m_Factory.factory;
            //txttop3.Text = m_Factory.factory;
            //txtavg1.Text = m_Factory.factory;//平均
            //txtavg2.Text = m_Factory.factory;
            //txtavg3.Text = m_Factory.factory;
            //txtlow1.Text = m_Factory.factory;//最低
            //txtlow2.Text = m_Factory.factory;
            //txtlow3.Text = m_Factory.factory;
            if (!string.IsNullOrEmpty(txtdesignNumber.Text)) m_Factory.designNumber = int.Parse(txtdesignNumber.Text);
            m_Factory.mDesignLongevity=txtmDesignLongevity.Text;
            if (!string.IsNullOrEmpty(txtchangeNumber.Text)) m_Factory.changeNumber = int.Parse(txtchangeNumber.Text);
            if (!string.IsNullOrEmpty(txtdevolopNumber.Text)) m_Factory.devolopNumber = int.Parse(txtdevolopNumber.Text);
            if (!string.IsNullOrEmpty(txtqcNumber.Text)) m_Factory.qcNumber = int.Parse(txtqcNumber.Text);
            if (!string.IsNullOrEmpty(txtdaySample.Text)) m_Factory.daySample = int.Parse(txtdaySample.Text);
            m_Factory.bmMaterial=txtbmMaterial.Text;
            m_Factory.accessory=txtaccessory.Text;
            m_Factory.outFactory=txtoutFactory.Text;
            if (!string.IsNullOrEmpty(txttprNumber.Text)) m_Factory.tprNumber = int.Parse(txttprNumber.Text);
            m_Factory.tprCanLoad=txttprCanLoad.Text;
            if (!string.IsNullOrEmpty(txttprDayProduct.Text)) m_Factory.tprDayProduct = int.Parse(txttprDayProduct.Text);
            if (!string.IsNullOrEmpty(txtmNumber.Text)) m_Factory.mNumber = int.Parse(txtmNumber.Text);
            m_Factory.mCanLoad=txtmCanLoad.Text;
            if (!string.IsNullOrEmpty(txtmDayProduct.Text)) m_Factory.mDayProduct = int.Parse(txtmDayProduct.Text);
            if (!string.IsNullOrEmpty(txtrbNumber.Text)) m_Factory.rbNumber = int.Parse(txtrbNumber.Text);
            m_Factory.rbCanload=txtrbCanload.Text;
            if (!string.IsNullOrEmpty(txtrbDayProduct.Text)) m_Factory.rbDayProduct = int.Parse(txtrbDayProduct.Text);
            if (!string.IsNullOrEmpty(txtsNumber.Text)) m_Factory.sNumber = int.Parse(txtsNumber.Text);
            m_Factory.sCanLoad=txtsCanLoad.Text;
            if (!string.IsNullOrEmpty(txtsDayProduct.Text)) m_Factory.sDayProduct = int.Parse(txtsDayProduct.Text);
            m_Factory.thx=txtthx.Text;
            if (!string.IsNullOrEmpty(txtthxDayProduct.Text)) m_Factory.thxDayProduct = int.Parse(txtthxDayProduct.Text);
            m_Factory.remark=txtremark3.Text;
            m_Factory.mName=txtmName.Text ;
            m_Factory.mPhone=txtmPhone.Text;
            m_Factory.mFax=txtmFax.Text;
            m_Factory.mAccountName=txtmAccountName.Text;
            m_Factory.mBank=txtmBank.Text ;
            m_Factory.mAccount=txtmAccount.Text ;
            m_Factory.Kind=cbKind.Text;
            m_Factory.gQcName=cbgQcName.Text;
            m_Factory.yName=cbyName.Text;
            m_Factory.xQcName=cbxQcName.Text;
            
            if (rbisCompleteship1.Checked) m_Factory.isComplete = "是";
            else if (rbisCompleteship2.Checked) m_Factory.isComplete = "否";
            if (rbfactoryStatus1.Checked) m_Factory.factoryStatus = "启动";
            else if (rbfactoryStatus2.Checked) m_Factory.factoryStatus = "禁用";
            for (n = 0; n < clbmainProduct.Items.Count; n++)
            {
                if (clbmainProduct.GetItemChecked(n))
                {
                    list+=1;
                }
                else list+=0;
            }
            m_Factory.mainProduct = list.ToString();

            for (n = 0; n < chbcheckDevice.Items.Count; n++)
            {
                if (chbcheckDevice.GetItemChecked(n))
                {
                    list += 1;
                }
                else list += 0;
            }
            m_Factory.checkDevice = list.ToString();
            db.T_Factory.Add(m_Factory);
            int i = db.SaveChanges();
            Msg.ShowInfo(string.Format("已保存{0}条订单信息。", i));
            this.panList.BringToFront();
            this.btn1.Text = "明细";
            this.IsQuery = true;
        }
        private void SaveModify()
        {
            if (m_Factory == null) return;
            m_Factory.factory = txtfactory.Text;
            m_Factory.fShort = txtfShort.Text;
            m_Factory.factoryFullName = txtfactoryFullName.Text;
            m_Factory.factoryFullNameEn = txtfactoryFullNameEn.Text;
            m_Factory.addressEn = txtaddressEn.Text;
            m_Factory.address = txtaddress.Text;
            if (!string.IsNullOrEmpty(txtlineNumber.Text)) m_Factory.lineNumber = int.Parse(txtlineNumber.Text);
            if (!string.IsNullOrEmpty(txtdayProduct.Text)) m_Factory.dayProduct = int.Parse(txtdayProduct.Text);
            if (!string.IsNullOrEmpty(txtlineLength.Text)) m_Factory.lineLength = int.Parse(txtlineLength.Text);
            m_Factory.zcNumber = txtzcNumber.Text;
            if (!string.IsNullOrEmpty(txtyearProduct.Text)) m_Factory.yearProduct = int.Parse(txtyearProduct.Text);
            //txt13.Text = m_Factory.factory;//主要客户贸易商
            //txt14.Text = m_Factory.factory;//该客户的主要市场和品牌
            m_Factory.kpzl = txtkpzl.Text;
            if (!string.IsNullOrEmpty(txtbankRoll.Text)) m_Factory.bankRoll = int.Parse(txtbankRoll.Text);
            m_Factory.phone = txtphone.Text;
            m_Factory.fax = txtfax.Text;
            m_Factory.email = txtemail.Text;
            m_Factory.homepage = txthomepage.Text;
            m_Factory.post = txtpost.Text;
            if (!string.IsNullOrEmpty(txtworkNumber.Text)) m_Factory.workNumber = int.Parse(txtworkNumber.Text);
            if (!string.IsNullOrEmpty(txtmanageNumber.Text)) m_Factory.manageNumber = int.Parse(txtmanageNumber.Text);
            //txtsh.Text = m_Factory.factory;//税号
            m_Factory.partnerStruct = txtpartnerStruct.Text;
            m_Factory.rmbBank = txtrmbBank.Text;
            m_Factory.rmbAccount = txtrmbAccount.Text;
            m_Factory.usdBank = txtusdBank.Text;
            m_Factory.usdAccount = txtusdAccount.Text;
            m_Factory.creditLevel = txtcreditLevel.Text;
            //txtremark1.Text = m_Factory.factory;//备注
            //txtml1.Text = m_Factory.factory;//面料
            //txtml2.Text = m_Factory.factory;
            //txtml3.Text = m_Factory.factory;
            //txtdd1.Text = m_Factory.factory;//大底
            //txtdd2.Text = m_Factory.factory;
            //txtdd3.Text = m_Factory.factory;
            //txttop1.Text = m_Factory.factory;//最高
            //txttop2.Text = m_Factory.factory;
            //txttop3.Text = m_Factory.factory;
            //txtavg1.Text = m_Factory.factory;//平均
            //txtavg2.Text = m_Factory.factory;
            //txtavg3.Text = m_Factory.factory;
            //txtlow1.Text = m_Factory.factory;//最低
            //txtlow2.Text = m_Factory.factory;
            //txtlow3.Text = m_Factory.factory;
            if (!string.IsNullOrEmpty(txtdesignNumber.Text)) m_Factory.designNumber = int.Parse(txtdesignNumber.Text);
            m_Factory.mDesignLongevity = txtmDesignLongevity.Text;
            if (!string.IsNullOrEmpty(txtchangeNumber.Text)) m_Factory.changeNumber = int.Parse(txtchangeNumber.Text);
            if (!string.IsNullOrEmpty(txtdevolopNumber.Text)) m_Factory.devolopNumber = int.Parse(txtdevolopNumber.Text);
            if (!string.IsNullOrEmpty(txtqcNumber.Text)) m_Factory.qcNumber = int.Parse(txtqcNumber.Text);
            if (!string.IsNullOrEmpty(txtdaySample.Text)) m_Factory.daySample = int.Parse(txtdaySample.Text);
            m_Factory.bmMaterial = txtbmMaterial.Text;
            m_Factory.accessory = txtaccessory.Text;
            m_Factory.outFactory = txtoutFactory.Text;
            if (!string.IsNullOrEmpty(txttprNumber.Text)) m_Factory.tprNumber = int.Parse(txttprNumber.Text);
            m_Factory.tprCanLoad = txttprCanLoad.Text;
            if (!string.IsNullOrEmpty(txttprDayProduct.Text)) m_Factory.tprDayProduct = int.Parse(txttprDayProduct.Text);
            if (!string.IsNullOrEmpty(txtmNumber.Text)) m_Factory.mNumber = int.Parse(txtmNumber.Text);
            m_Factory.mCanLoad = txtmCanLoad.Text;
            if (!string.IsNullOrEmpty(txtmDayProduct.Text)) m_Factory.mDayProduct = int.Parse(txtmDayProduct.Text);
            if (!string.IsNullOrEmpty(txtrbNumber.Text)) m_Factory.rbNumber = int.Parse(txtrbNumber.Text);
            m_Factory.rbCanload = txtrbCanload.Text;
            if (!string.IsNullOrEmpty(txtrbDayProduct.Text)) m_Factory.rbDayProduct = int.Parse(txtrbDayProduct.Text);
            if (!string.IsNullOrEmpty(txtsNumber.Text)) m_Factory.sNumber = int.Parse(txtsNumber.Text);
            m_Factory.sCanLoad = txtsCanLoad.Text;
            if (!string.IsNullOrEmpty(txtsDayProduct.Text)) m_Factory.sDayProduct = int.Parse(txtsDayProduct.Text);
            m_Factory.thx = txtthx.Text;
            if (!string.IsNullOrEmpty(txtthxDayProduct.Text)) m_Factory.thxDayProduct = int.Parse(txtthxDayProduct.Text);
            m_Factory.remark = txtremark3.Text;
            m_Factory.mName = txtmName.Text;
            m_Factory.mPhone = txtmPhone.Text;
            m_Factory.mFax = txtmFax.Text;
            m_Factory.mAccountName = txtmAccountName.Text;
            m_Factory.mBank = txtmBank.Text;
            m_Factory.mAccount = txtmAccount.Text;
            m_Factory.Kind = cbKind.Text;
            m_Factory.gQcName = cbgQcName.Text;
            m_Factory.yName = cbyName.Text;
            m_Factory.xQcName = cbxQcName.Text;
            if (rbisCompleteship1.Checked) m_Factory.isComplete = "是";
            else if (rbisCompleteship2.Checked) m_Factory.isComplete = "否";
            if (rbfactoryStatus1.Checked) m_Factory.factoryStatus = "启动";
            else if (rbfactoryStatus2.Checked) m_Factory.factoryStatus = "禁用";
            for (n = 0; n < clbmainProduct.Items.Count; n++)
            {
                if (clbmainProduct.GetItemChecked(n))
                {
                    list += 1; ;
                }
                else list+=0;
            }
            m_Factory.mainProduct = list.ToString();
            for (n = 0; n < chbcheckDevice.Items.Count; n++)
            {
                if (chbcheckDevice.GetItemChecked(n))
                {
                    list += 1;
                }
                else list += 0;
            }
            m_Factory.checkDevice = list.ToString();
            int i=db.SaveChanges();
            Msg.ShowInfo(string.Format("已保存{0}条订单信息。", i));
            this.panList.BringToFront();
            this.btn1.Text = "明细";
            this.IsQuery = true;
        }
        public frmSupplier()
        {
            InitializeComponent();
            panList.BringToFront();
            gvDataSource();
        }
        private void gvDataSource()
        {
            var list = db.T_Factory.ToList();
            bslist.DataSource = list;
            bnavlist.BindingSource = bslist;
        }
        private void TxtClear()
        {
            Helper.TxtClear(txtfactory);
            Helper.TxtClear(txtfShort);
            Helper.TxtClear(txtfactoryFullName);
            Helper.TxtClear(txtfactoryFullNameEn);
            Helper.TxtClear(txtaddress);
            Helper.TxtClear(txtaddressEn);
            Helper.TxtClear(txtlineNumber);
            Helper.TxtClear(txtdayProduct);
            Helper.TxtClear(txtlineLength);
            Helper.TxtClear(txtzcNumber);
            Helper.TxtClear(txtyearProduct);
            Helper.TxtClear(txt13);//主要客户贸易商
            Helper.TxtClear(txt14);//该客户的主要市场和品牌
            Helper.TxtClear(txtkpzl);
            Helper.TxtClear(txtbankRoll);
            Helper.TxtClear(txtphone);
            Helper.TxtClear(txtfax);
            Helper.TxtClear(txtemail);
            Helper.TxtClear(txthomepage);
            Helper.TxtClear(txtpost);
            Helper.TxtClear(txtworkNumber);
            Helper.TxtClear(txtmanageNumber);
            Helper.TxtClear(txtsh);//税号
            Helper.TxtClear(txtpartnerStruct);
            Helper.TxtClear(txtrmbBank);
            Helper.TxtClear(txtrmbAccount);
            Helper.TxtClear(txtusdBank);
            Helper.TxtClear(txtusdAccount);
            Helper.TxtClear(txtcreditLevel);
            //Helper.TxtClear(txtfactory);
            Helper.TxtClear(txtremark1);
            Helper.TxtClear(txtml1);//面料
            Helper.TxtClear(txtml2);
            Helper.TxtClear(txtml3);
            Helper.TxtClear(txtdd1);//大底
            Helper.TxtClear(txtdd2);
            Helper.TxtClear(txtdd3);
            Helper.TxtClear(txttop1);//最高
            Helper.TxtClear(txttop2);
            Helper.TxtClear(txttop3);
            Helper.TxtClear(txtavg1);//平均
            Helper.TxtClear(txtavg2);
            Helper.TxtClear(txtavg3);
            Helper.TxtClear(txtlow1);//最低
            Helper.TxtClear(txtlow2);
            Helper.TxtClear(txtlow3);
            Helper.TxtClear(txtdaySample);
            Helper.TxtClear(txtdesignNumber);
            Helper.TxtClear(txtmDesignLongevity);
            Helper.TxtClear(txtchangeNumber);
            Helper.TxtClear(txtdevolopNumber);
            Helper.TxtClear(txtqcNumber);
            Helper.TxtClear(txttprNumber);
            Helper.TxtClear(txtbmMaterial);
            Helper.TxtClear(txtaccessory);
            Helper.TxtClear(txtoutFactory);
            Helper.TxtClear(txttprCanLoad);
            Helper.TxtClear(txttprDayProduct);
            Helper.TxtClear(txtmNumber);
            Helper.TxtClear(txtmCanLoad);
            Helper.TxtClear(txtmDayProduct);
            Helper.TxtClear(txtrbNumber);
            Helper.TxtClear(txtrbCanload);
            Helper.TxtClear(txtrbDayProduct);
            Helper.TxtClear(txtsNumber);
            Helper.TxtClear(txtsCanLoad);
            Helper.TxtClear(txtsDayProduct);
            Helper.TxtClear(txtthx);
            Helper.TxtClear(txtthxDayProduct);
            Helper.TxtClear(txtremark3);
            Helper.CBClear(cbKind);
            Helper.CBClear(cbgQcName);
            Helper.CBClear(cbyName);
            Helper.CBClear(cbxQcName);
            rbisCompleteship1.Checked = true;
            rbisCompleteship2.Checked = true;
            rbfactoryStatus1.Checked = true;
            rbfactoryStatus2.Checked = true;
            Helper.TxtClear(txtmName);
            Helper.TxtClear(txtmPhone);
            Helper.TxtClear(txtmFax);
            Helper.TxtClear(txtmAccountName);
            Helper.TxtClear(txtmBank);
            Helper.TxtClear(txtmAccount);
            for (int n = 0; n < clbmainProduct.Items.Count; n++)
            {
                clbmainProduct.SetItemChecked(n, false);
            }
            for (int n = 0; n < chbcheckDevice.Items.Count; n++)
            {
                chbcheckDevice.SetItemChecked(n, false);
            }
        }

        private void btn1_Click(object sender, EventArgs e)
        {
            gvID();
            if(this.IsQuery)
            {
                this.panList.BringToFront();
                btn1.Text = "明细";
                this.IsQuery = false;
            }
            else
            {
                this.panDetail.BringToFront();
                btn1.Text = "概要";
                this.IsQuery = true;
            }
        }

        private void btnBack_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            m_Factory = null;
            this.panDetail.BringToFront();
            btn1.Text = "概要";
            this.IsQuery = false;
            TxtClear();

        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            if (Msg.ShowWarning("尚未保存，您确定要取消吗？") == System.Windows.Forms.DialogResult.Yes)
            {
                this.panList.BringToFront();
                this.btn1.Text = "明细";
                this.IsQuery = true;

            }
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            btn1_Click(null, null);
        }

        private void btnDel_Click(object sender, EventArgs e)
        {
            if (Msg.ShowWarning("您确信删除此信息吗？") == System.Windows.Forms.DialogResult.Yes)
            {
                gvID();
                if(m_factory==0)
                {
                    Msg.ShowError("请选择一条记录！");
                    return;
                }
                var outfactory = db.T_Factory.First(a=>a.fID==m_factory);
                db.T_Factory.Remove(outfactory);
                int i=db.SaveChanges();
                Msg.ShowInfo(string.Format("已删除{0}条订单信息。", i));
                gvDataSource();
            }
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (Msg.ShowWarning("您确信保存订单信息吗？") == System.Windows.Forms.DialogResult.Yes)
            {
                if(m_Factory==null)
                {
                    SaveAdd();
                    gvDataSource();
                    this.panList.BringToFront();
                    this.btn1.Text = "明细";
                    this.IsQuery = true;

                }
                else
                {
                    SaveModify();
                    gvDataSource();
                    this.panList.BringToFront();
                    this.btn1.Text = "明细";
                    this.IsQuery = true;

                }
            }
        }

        private void gvlist_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                this.factory = Convert.ToInt32(gvlist.Rows[e.RowIndex].Cells["colfID"].Value.ToString());
                this.panDetail.BringToFront();
                btn1.Text = "概要";
                this.IsQuery = false;
            }
            catch (Exception)
            {

                Msg.ShowError("请选择表里的数据！");
            }
        }

        private void frmSupplier_Load(object sender, EventArgs e)
        {
            Service.Buyer(cbyName);

            Service.QC(cbxQcName);

            Service.QC(cbgQcName);
        }

    }
}
